package gis.lifay.sdk.jts;

import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 *@ClassName JtsTest
 *@Description TODO
 *@Author lifay
 *@Date 2021/11/6 7:40
 **/
public class JtsTest {


    // 几何工厂对象
    private static GeometryFactory geometryFactory = new GeometryFactory();

    public static void main(String[] args) throws ParseException {
        WKTReader reader = new WKTReader(geometryFactory);
        //多边形
        Polygon polygon = (Polygon) reader.read("POLYGON ((0 0, 7200 0, 7200 3600, 0 3600, 0 0))");
        String polygonStr = polygon.toText();
        System.out.println(polygonStr);
        //点
        Point point = (Point) reader.read("POINT (20 10)");
        String pointStr = point.toText();
        System.out.println(pointStr);

        System.out.println(polygon.within(point));
        System.out.println(point.within(polygon));

        Point point1 = JTSGeometryUtil.getPoint((double) 1800, (double) 2000);

        System.out.println(point1.isEmpty());
        System.out.println(polygon.contains(point1));
    }
}